#include"../common/blockingqueue.h"
#include<unistd.h>


void* test(void *args){
    blockingqueue* bq=(blockingqueue*)args;
    for(int i=0;i<5;i++){
        void* data=bq_poll(bq);
        int* num_ptr=(int*)data;
        printf("%ld bq poll : %d\n",pthread_self(),*num_ptr);
    }
    for(int i=0;i<5;i++){
        void* data=bq_ub_poll(bq,2);
        if(data==NULL){
            printf("%ld bq poll : NULL\n",pthread_self());
        }else{
            int* num_ptr=(int*)data;
            printf("%ld bq poll : %d\n",pthread_self(),*num_ptr);
        }
    }
    return NULL;
}

int main(){
    blockingqueue* bq=create_blockingqueue();
    pthread_t tid;
    pthread_create(&tid,NULL,test,(void*)bq);
    pthread_t tid1;
    pthread_create(&tid1,NULL,test,(void*)bq);
    for(int i=0;i<20;i++){
        int* data=(int*)calloc(1,sizeof(int));
        *data=i;
        printf("push :%d\n",*data);
        bq_push(bq,data);
        //free(data);
    }

    pthread_join(tid,NULL);
    pthread_join(tid1,NULL);

    return 0;
}